#include <algorithm>
#include <iostream>
using namespace std;
#define MAXN 305
#define MAXM 100005
struct edge{
    int a, b, w;
    bool operator <(const edge &y)const{
        return w < y.w;
    }
}e[MAXM];

int fa[MAXN];
int find(int x){
    return fa[x] == x ? x : fa[x] = find(fa[x]);
}
int main() {
    int n, m;
    cin >> n >> m;
    for(int i=1; i<=n; i++) fa[i] = i;
    int s = 0, smax = 0;
    for(int i=1; i<=m; ++i){
        cin >> e[i].a >> e[i].b >> e[i].w;
    }

    sort(e+1, e+1+m);

    for(int i=1; i<=m; ++i){
        if(find(e[i].a) == find(e[i].b)) continue;
        fa[find(e[i].a)] = find(e[i].b);
        s++;
        smax = e[i].w;
    }
    cout << s << " " << smax;

    return 0;
}
